import { reqGetOrder, reqPayOrder } from "@/api";

const state = {
    goodsList:[],
    totalPrice:0,
    orderId:0,
};
const actions = {
    // 生成订单
    async getOrder({commit}){
        let result = await reqGetOrder();
        if(result.code == 200){
            commit("GETORDER",result.data);
            return 'ok';
        }else{
            return Promise.reject(result.msg);
        }
    },
    // 支付订单
    async payOrder({commit},orderId){
        let result = await reqPayOrder(orderId);
        if(result.code == 200){
            return 'ok';
        }else{
            return Promise.reject(result.msg);
        }
    }
};
const mutations = {
    GETORDER(state,{goodsList,totalPrice,orderId}){
        state.goodsList = goodsList;
        state.totalPrice = totalPrice;
        state.orderId = orderId;
    }
};
const getters = {};

export default {
    namespaced: true,
    state, 
    actions, 
    mutations, 
    getters
}